package com.bilibili.juc.interrupt;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class InterruptTestDemo03 {

    //static volatile boolean isStop = false;
    //static  boolean isStop = false ;

    //static AtomicBoolean isStop = new AtomicBoolean(false) ;


    public static void main(String[] args) {
        Thread t1 = new Thread(
                ()->{
                    while(true){
                        if(Thread.currentThread().isInterrupted()){
                            System.out.println(Thread.currentThread().getName()+"\t 被中断 修改为ture,程序停止");
                            break;
                        }
                        System.out.println("---- hello interruptAPI t1");
                    }

                },"t1"
        );
        t1.start();

        try{
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        new Thread(
                ()->{
                    System.out.println(Thread.currentThread().getName()+"-------");
                    t1.interrupt();
                    System.out.println(Thread.currentThread().getName()+"after-------");
                },"t2"
        ).start();

        System.out.println(Thread.currentThread().getName()+"-------");
    }
}
